package 链表;

import java.util.HashSet;

/**
 * @Author：小鹿爱吃鱼
 * @Date: 2025/5/7 21:34
 * @Description:
 */
public class 环形链表 {

    // 简简单单用hash得了
    public boolean hasCycle(ListNode head) {
        HashSet<ListNode> set = new HashSet<>();
        while (head != null){
            if(set.contains(head)){
                return true;
            }else{
                set.add(head);
            }
            head = head.next;
        }
        return false;
    }

    public static void main(String[] args) {

    }


    private static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }



}
